package com.itheima02.Day09;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * @author 刘全
 * @date 2021/7/26
 */
//先判断分数,再判断年龄,最后以首字母判断
public class Test5 {
    public static void main(String[] args) {
        Student stu1 = new Student("zhangsan",23,83);
        Student stu2 = new Student("lisi",24,94);
        Student stu3 = new Student("wangwu",23,84);
        Student stu4 = new Student("zhaoliu",23,83);
        TreeSet<Student> ts = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int result = o1.getScore() - o2.getScore();
                result = result == 0 ? o1.getAge() - o2.getAge() : result;
                result = result == 0 ? o1.compareTo(o2) : result;
                return result;
            }
        });
        ts.add(stu1);
        ts.add(stu2);
        ts.add(stu3);
        ts.add(stu4);
        for (Student t : ts) {
            System.out.println(t);
        }
    }
}
